package com.ruoyi.hotel.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.hotel.domain.bo.HmRoomTypeBo;
import com.ruoyi.hotel.domain.vo.HmRoomTypeVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.service.IHmRoomTypeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间类型管理
 *
 * @date 2023-10-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hotel/roomType")
public class HmRoomTypeController extends BaseController {

    private final IHmRoomTypeService iHmRoomTypeService;

    /**
     * 查询房间类型列表
     */
    @SaCheckPermission("hotel:roomType:list")
    @GetMapping("/list")
    public TableDataInfo<HmRoomTypeVo> list(HmRoomTypeBo bo, PageQuery pageQuery) {
        return iHmRoomTypeService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取房间类型详细信息
     *
     * @param roomType 主键
     */
    @SaCheckPermission("hotel:roomType:query")
    @GetMapping("/{roomType}")
    public R<HmRoomTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String roomType) {
        return R.ok(iHmRoomTypeService.queryById(roomType));
    }

    /**
     * 新增房间类型
     */
    @SaCheckPermission("hotel:roomType:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HmRoomTypeBo bo) {
        return toAjax(iHmRoomTypeService.insertByBo(bo));
    }

    /**
     * 修改房间类型
     */
    @SaCheckPermission("hotel:roomType:edit")
    @Log(title = "修改房间类型", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HmRoomTypeBo bo) {
        return toAjax(iHmRoomTypeService.updateByBo(bo));
    }

    /**
     * 删除房间类型
     *
     * @param roomTypes 主键串
     */
    @SaCheckPermission("hotel:roomType:remove")
    @Log(title = "删除房间类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roomTypes}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] roomTypes) {
        return toAjax(iHmRoomTypeService.deleteWithValidByIds(Arrays.asList(roomTypes), true));
    }
}
